{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Plotting an ROC Curve without Context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data_web_address = \"https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data\"\n",
    "column_names = ['pregnancy_x', \n",
    "                'plasma_con', \n",
    "                'blood_pressure', \n",
    "                'skin_mm', \n",
    "                'insulin', \n",
    "                'bmi', \n",
    "                'pedigree_func', \n",
    "                'age', \n",
    "                'target']\n",
    "\n",
    "feature_names = column_names[:-1]\n",
    "all_data = pd.read_csv(data_web_address , names=column_names)\n",
    "all_data.head()\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "X = all_data[feature_names]\n",
    "y = all_data['target']\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=7,stratify=y)\n",
    "\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression()\n",
    "lr.fit(X_train,y_train)\n",
    "\n",
    "y_pred = lr.predict(X_test)\n",
    "y_pred_proba = lr.predict_proba(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0xd327048>]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAEACAYAAABWLgY0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADq9JREFUeJzt3V+IZGeZx/HvL85mYSWGjIGAExN2oyEoRhGdnYvAlols\nOt6MeLNJIGJAGNiNeGeSC5m+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V5AH4L7Fl27XOYizuA9wAvrPP+VLk5jyN5Pzx1xdi5qKpnqur3/c1naPfzBZP8XAB8\nAvgm8JtFFrdgk8zF/cDjVXUeoKpeXXCNizLJXBRwTf/5NcBvq+pPC6xxIarqKWBtgyFT5eY8Qt4P\nT10xyVwM+jjwnblWtDxj5yLJW4APV9WXgJavxJrk5+JWYG+SJ5OcSPLAwqpbrEnm4jHgHUleBp4H\nPrmg2rabqXJzkksotQBJPkDvqqQ7ll3LEn0eGOzJthz04+wB3gvcCbwReDrJ01X14nLLWoq7gWer\n6s4ktwDfS3J7Vf1h2YXtBPMI+fPATQPbN/ZfGx7z1jFjWjDJXJDkduAIsFJVG/13bSebZC7eBxxL\nEnq913uSXKyq4wuqcVEmmYtzwKtV9RrwWpIfAO+m179uySRz8SDwWYCq+kWS/wNuA368kAq3j6ly\ncx7tmssfnkpyNb0PTw3/kh4HPgqXP1E78sNTDRg7F0luAh4HHqiqXyyhxkUZOxdV9Xf9x9/S68v/\nc4MBD5P9jvwHcEeSNyT5G3on2k4uuM5FmGQuzgIfBOj3oG8FfrnQKhcnrP8/2Klyc+ZH8uWHpy6b\nZC6ATwN7gS/2j2AvVtX+5VU9HxPOxZ99ycKLXJAJf0dOJfku8AJwCThSVT9bYtlzMeHPxWeArw5c\nWvipqrqwpJLnJsnXgQ7w5iS/Ag4DV7PF3PTDUJLUMFehlKSGGfKS1DBDXpIaZshLUsMMeUlqmCEv\nSQ0z5CWpYYa8JDXs/wH9Y/d11KrMdQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x3e61b38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "fpr, tpr, ths = roc_curve(y_test, y_pred_proba[:,1])\n",
    "plt.plot(fpr,tpr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.82518518518518524"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import auc\n",
    "\n",
    "auc(fpr,tpr)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
